home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_cloudplane.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.5 KB  |  61 lines

  1. /* I took wave's lead and renamed cloudplane to DPCloudplane.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /* 
  4.  * cloudplane.sl
  5.  *
  6.  * AUTHOR: Darwyn Peachy
  7.  *
  8.  * REFERENCES:
  9.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  10.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  11.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  12.  */
  13.  
  14. #include "k3d_proctext.h"
  15.  
  16. #define NTERMS 5
  17.  
  18. surface
  19. k3d_cloudplane(
  20.     color cloudcolor = color (1,1,1);
  21.     )
  22. {
  23.     color Ct;
  24.     point Psh;
  25.     float i, amplitude, f;
  26.     float x, fx, xfreq, xphase;
  27.     float y, fy, yfreq, yphase;
  28.     uniform float offset = 0.5;
  29.     uniform float xoffset = 13;
  30.     uniform float yoffset = 96;
  31.     
  32.     Psh = transform("shader", P);
  33.     x = xcomp(Psh) + xoffset;
  34.     y = ycomp(Psh) + yoffset;
  35.  
  36.     xphase = 0.9; /* arbitrary */
  37.     yphase = 0.7; /* arbitrary */
  38.     xfreq = 2 * PI * 0.023;
  39.     yfreq = 2 * PI * 0.021;
  40.     amplitude = 0.3;
  41.     f = 0;
  42.     for (i = 0; i < NTERMS; i += 1) {
  43.         fx = amplitude *
  44.             (offset + cos(xfreq * (x + xphase)));
  45.         fy = amplitude *
  46.             (offset + cos(yfreq * (y + yphase)));
  47.         f += fx * fy;
  48.         xphase = PI/2 * 0.9 * cos(yfreq * y);
  49.         yphase = PI/2 * 1.1 * cos(xfreq * x);
  50.     
  51.         xfreq *= 1.9 + i * 0.1; /* approximately 2 */
  52.         yfreq *= 2.2 - i * 0.08; /* approximately 2 */
  53.         amplitude *= 0.707;
  54.     }
  55.     f = clamp(f, 0, 1);
  56.  
  57.     Ct = mix(Cs, cloudcolor, f);
  58.     Oi = Os;
  59.     Ci = Os * Ct;
  60. }
  61.